package com.warm.demo.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.warm.core.domain.R;
import com.warm.core.page.BaseController;
import com.warm.core.page.TableDataInfo;
import com.warm.demo.api.dto.TestCommonDto;
import com.warm.demo.api.vo.TestCommonVo;
import com.warm.demo.service.ITestCommonService;
import com.warm.log.annotation.Log;
import com.warm.log.enums.BusinessType;
import com.warm.mybatis.domain.QueryParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.noear.solon.annotation.*;
import org.noear.solon.validation.annotation.Valid;

/**
 * 常规演示Controller
 *
 * @author warm
 */
@Api(value = "常规演示控制器", tags = {"常规演示管理"})
@Valid
@Controller
@Mapping("/test/common")
public class TestCommonController extends BaseController {
    @Inject
    private ITestCommonService testCommonService;

    /**
     * 分页查询常规演示列表
     */
    @ApiOperation("分页查询常规演示列表")
    @SaCheckPermission("test:common:list")
    @Get
    @Mapping("/list")
    public TableDataInfo<TestCommonVo> list(QueryParam queryParam, TestCommonDto dto) {
        return testCommonService.selectPage(queryParam, dto);
    }


    /**
     * 获取常规演示详细信息
     */
    @ApiOperation("获取常规演示详细信息")
    @SaCheckPermission("test:common:query")
    @Get
    @Mapping(value = "/{id}")
    public R<TestCommonVo> getInfo(Long id) {
        return R.ok(testCommonService.selectById(id));
    }

    /**
     * 新增常规演示
     */
    @ApiOperation("新增常规演示")
    @SaCheckPermission("test:common:add")
    @Log(title = "常规演示", businessType = BusinessType.INSERT)
    @Post
    @Mapping
    public R<Void> add(TestCommonDto dto) {
        return toR(testCommonService.insertByDto(dto));
    }

    /**
     * 修改常规演示
     */
    @ApiOperation("修改常规演示")
    @SaCheckPermission("test:common:edit")
    @Log(title = "常规演示", businessType = BusinessType.UPDATE)
    @Put
    @Mapping
    public R<Void> edit(TestCommonDto dto) {
        return toR(testCommonService.updateByDto(dto));
    }

    /**
     * 删除常规演示
     */
    @ApiOperation("删除常规演示")
    @SaCheckPermission("test:common:remove")
    @Log(title = "常规演示", businessType = BusinessType.DELETE)
    @Delete
    @Mapping("/{ids}")
    public R<Void> remove(Long[] ids) {
        return toR(testCommonService.deleteByIds(ids));
    }
}
